layui.use(['form', 'jquery', 'jquery_cookie'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);

    /**
     * 表单的submit监听
     */
    form.on('submit(saveBtn)', function (data) {
        console.log(data);

        $.ajax({
            type: "post",
            url: ctx + "/user/updatePwd",
            data: {
                oldPassword: data.field.old_password,
                oldPassword: data.field.new_password,
                repeatPassword: data.field.again_password
            },
            success: function (result) {
                if (result.code == 200) {
                    //成功
                    layer.msg("修改成功，系统将在3秒钟后跳转...", function () {

                        $.removeCookie("userIdStr", {domain: "localhost", path: "/crm"});
                        $.removeCookie("userIdStr", {domain: "localhost", path: "/crm"});
                        $.removeCookie("userIdStr", {domain: "localhost", path: "/crm"});

                        //父窗口跳转
                        window.parent.location.href = ctx + "/index";
                    });
                } else {
                    //失败
                    layer.msg(result.msg, {icon: 5});
                }

            }
        });
    })

});